<template>
	<div>
		<cus-modal
			ref="modal"
			:center="true"
			title="审核意见"
			:showOtherBtn="true"
			otherBtnType="error"
			:showCancelBtn="false"
			@on-visible-change="onVisibleChange"
		>
			<div
				:style="{ height: data.length > 0 ? '190px' : '' }"
				style="overflow-y: auto; overflow-x: hidden"
			>
				<div class="mb_10" v-for="(item, index) in data" :key="index">
					<div class="fl mb_10">
						<div>{{ `${index + 1}、${item.gmtCreate}` }}</div>
						<div class="text ml_24">{{ item.applyComment }}</div>
					</div>
					<div>
						<p class="ml_10" style="padding: 0 10px 0 0">
							{{ item.auditComment ? item.auditComment : '暂无!' }}
						</p>
					</div>
				</div>
			</div>
			<div>
				<Input
					v-model="auditComment"
					type="textarea"
					maxlength="100" show-word-limit
					:autosize="{ minRows: 5, maxRows: 10 }"
					placeholder="请输入审核意见"
				></Input>
			</div>
			<div slot="footer">
				<slot name="footer">
					<div class="modal-footer">
						<cus-button
							size="small"
							type="error"
							class="mr_2"
							v-if="form.organAuditState != 2 && form.organAuditState != 3"
							@onClick="onReject()"
							>驳回</cus-button
						>
						<cus-button
							v-if="form.organAuditState != 2 && form.organAuditState != 3"
							type="success"
							size="small"
							@onClick="onOk()"
							>通过</cus-button
						>
						<cus-button
							v-if="form.organAuditState == 2 && form.organAuditState != 3"
							type="primary"
							size="small"
							@onClick="onCancel()"
							>撤销审核</cus-button
						>
					</div>
				</slot>
			</div>
			<Spin size="large" fix v-if="loading"></Spin>
		</cus-modal>
	</div>
</template>

<script>
import {
	getCookbookLog,
	auditCookbook,
	rejectCookbook,
	backOutCookbook
} from '@/api/organ/dishesModule'
export default {
	name: 'recipeModal',
	data() {
		return {
			loading: false,
			auditComment: '',
			form: {},
			data: []
		}
	},
	mounted() {},
	methods: {
		// 审核日志-----------------------接口
		getCookbookLog() {
			this.loading = true
			return new Promise((resolve) => {
				getCookbookLog({ mealPlanId: this.form.mealPlanId }).then((res) => {
					this.loading = false
					if (res.code === 1) {
						this.data = res.data
						resolve()
					}
				})
			})
		},
		//通过食谱审核
		auditCookbook(params) {
			auditCookbook(params).then((res) => {
				if (res.code == 1) {
					this.$Message.success('食谱审核成功')
					this.$refs['modal'].show = false
					this.$emit('refetch')
				}
			})
		},
		//驳回食谱
		rejectCookbook(params) {
			rejectCookbook(params).then((res) => {
				if (res.code == 1) {
					this.$Message.success('食谱驳回成功')
					this.$refs['modal'].show = false
					this.$emit('refetch')
				}
			})
		},
		//撤消食谱
		backOutCookbook(params) {
			backOutCookbook(params).then((res) => {
				if (res.code == 1) {
					this.$Message.success('撤销食谱成功')
					this.$refs['modal'].show = false
					this.$emit('refetch')
				}
			})
		},
		onVisibleChange(v) {
            if (!v) {
				this.auditComment = '';
            }
		},
		show(data) {
			this.loading = false
			this.form = data
			this.$refs['modal'].show = true
			this.getCookbookLog()
		},
		onOk() {
			let params = new Object()
			params.auditComment = this.auditComment
			params.mealPlanIds = new Array()
			params.mealPlanIds.push(this.form.mealPlanId)
			this.auditCookbook(params)
		},
		onReject() {
			let params = new Object()
			params.auditComment = this.auditComment
			params.mealPlanId = this.form.mealPlanId
			this.rejectCookbook(params)
		},
		onCancel() {
			let params = new Object()
			params.auditComment = this.auditComment
			params.mealPlanId = this.form.mealPlanId
			this.backOutCookbook(params)
		}
	}
}
</script>

<style scoped lang="less">
.permission {
	/*height: 300px;*/
	width: 500px;
	border: 1px solid #dcdee2;
	overflow-y: auto;
	overflow-x: hidden;
	border-radius: 2px;
	padding: 0 0 0 10px;
}

.permission::-webkit-scrollbar {
	display: none;
}
.fl {
  display: flex;
}
.text {
  font-size: 14px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #1e6fff;
}
</style>
